from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload_data():
    data = request.get_json()
    print("收到数据:", data)  # 打印到终端
    # 保存数据到文件（可改为数据库）
    with open('data.txt', 'a') as f:
        f.write(str(data) + '\n')
    return jsonify({"message": "数据上传成功"}), 200

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
